#!/bin/bash

#添加主机到zabbix#2021年9月23日19点59分

serverIP=172.27.16.100

yum -y install redhat-lsb-core > /dev/null 2>&1

#判断系统类型
sys=`lsb_release -a 2> /dev/null | grep "Distributor ID:" | awk -F ' ' '{print $3}'`
if [ $sys = "Ubuntu" ]
then
    wget https://repo.zabbix.com/zabbix/5.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.4-1+ubuntu20.04_all.deb
    dpkg -i zabbix-release_5.4-1+ubuntu20.04_all.deb
	apt update
    apt -y install zabbix-agent
    sed -i "s/Server=127.0.0.1/Server=$serverIP/g" /etc/zabbix/zabbix_agentd.conf
    sed -i "s/ServerActive=127.0.0.1/ServerActive=$serverIP/g" /etc/zabbix/zabbix_agentd.conf
    systemctl restart zabbix-agent
    systemctl enable zabbix-agent
else
    if [ $sys = "CentOS" ]
    then
        yum -y install https://mirrors.aliyun.com/zabbix/zabbix/5.4/rhel/7/x86_64/zabbix-release-5.4-1.el7.noarch.rpm
		yum clean all && yum repolist
        yum -y install zabbix-agent
        sed -i "s/Server=127.0.0.1/Server=$serverIP/g" /etc/zabbix/zabbix_agentd.conf
        sed -i "s/ServerActive=127.0.0.1/ServerActive=$serverIP/g" /etc/zabbix/zabbix_agentd.conf
        systemctl restart zabbix-agent
        systemctl enable zabbix-agent
    fi
fi